package cn.knowei.day2.jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class DBDemo {
    Connection con;
    PreparedStatement ps;

    public int addDB() {
        int flag = 0;
        try {
            con = DBUtils.getConnection();
            String sql = "insert into students(username, password) values (?, ?)";
            ps = con.prepareStatement(sql);

            ps.setString(1, "zww");
            ps.setString(2, "123");

            flag = ps.executeUpdate();

        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return flag;
    }

    public static void main(String[] args) {
        DBDemo dbDemo = new DBDemo();
        int flag = dbDemo.addDB();
        if (flag == 1) {
            System.out.println("success");
        }
    }
}
